package one;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Mian {
    public static void main(String[] args) throws SQLException {
        /**
         * //不要全部一起测试，这样看不出效果。测试一个去掉注释注释。例如
         *         insert();
         * //        delete();
         * //        update();
         * //       select();
         *   再或者
         * //          insert();
         *        delete();
         * //        update();
         * //        select();
         * 一直测试下去
         */

        insert();
//        delete();
//        update();
        select();
    }
    public static void insert() throws SQLException {
        User user1 = new User();
        user1.setId(7);
        user1.setAge(27);
        user1.setName("测试插入");
        //测试数据库插入数据
        JDBC_ORM.ORM_INSERT(user1);
        System.out.println("插入成功，请查看数据库！");
    }
        public static void update(){
            User user3 = new User();
            user3.setId(8);
            user3.setAge(28);
            user3.setName("测试更新");
            //测试更新
            JDBC_ORM.ORM_UPDATE(user3, "id", "7");
            System.out.println("更新成功，请查看数据库！");
        }

        public static void delete(){
            User user2 = new User();
            user2.setId(7);
            //测试数据库删除数据
            JDBC_ORM.ORM_DELETE(user2);
            System.out.println("删除成功，请查看数据库！");
        }

        public static void select() throws SQLException {
            User user4 = new User();
            user4.setId(7);
            user4.setAge(27);
            //测试递归查询
            ResultSet resultSet1 = JDBC_ORM.ORM_QUERY(user4, "id", "7", "age", "27");
            while (resultSet1.next()) {
                System.out.println(resultSet1.getInt(1));
                System.out.println(resultSet1.getString(2));
                System.out.println(resultSet1.getInt(3));
            }

            //测试一个查询
            ResultSet resultSet2 = JDBC_ORM.ORM_QUERY(user4, "id", "1");
            while (resultSet2.next()) {
                System.out.println(resultSet2.getInt(1));
                System.out.println(resultSet2.getString(2));
                System.out.println(resultSet2.getInt(3));
            }

            //测试全部查询
            ResultSet resultSet3 = JDBC_ORM.ORM_QUERY(user4);
            while (resultSet3.next()) {
                System.out.println(resultSet3.getInt(1));
                System.out.println(resultSet3.getString(2));
                System.out.println(resultSet3.getInt(3));
            }
        }
}
